using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace CXDB
{
	/// <summary>
	/// Strongly-typed collection for the CxUserBase class.
	/// </summary>
    [Serializable]
	public partial class CxUserBaseCollection : ActiveList<CxUserBase, CxUserBaseCollection>
	{	   
		public CxUserBaseCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>CxUserBaseCollection</returns>
		public CxUserBaseCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                CxUserBase o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the CX_UserBase table.
	/// </summary>
	[Serializable]
	public partial class CxUserBase : ActiveRecord<CxUserBase>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public CxUserBase()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public CxUserBase(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public CxUserBase(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public CxUserBase(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CX_UserBase", TableType.Table, DataService.GetInstance("CXDB"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarUID = new TableSchema.TableColumn(schema);
				colvarUID.ColumnName = "uID";
				colvarUID.DataType = DbType.Int32;
				colvarUID.MaxLength = 0;
				colvarUID.AutoIncrement = true;
				colvarUID.IsNullable = false;
				colvarUID.IsPrimaryKey = true;
				colvarUID.IsForeignKey = false;
				colvarUID.IsReadOnly = false;
				colvarUID.DefaultSetting = @"";
				colvarUID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUID);
				
				TableSchema.TableColumn colvarUsername = new TableSchema.TableColumn(schema);
				colvarUsername.ColumnName = "username";
				colvarUsername.DataType = DbType.String;
				colvarUsername.MaxLength = 50;
				colvarUsername.AutoIncrement = false;
				colvarUsername.IsNullable = true;
				colvarUsername.IsPrimaryKey = false;
				colvarUsername.IsForeignKey = false;
				colvarUsername.IsReadOnly = false;
				colvarUsername.DefaultSetting = @"";
				colvarUsername.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUsername);
				
				TableSchema.TableColumn colvarPassWD = new TableSchema.TableColumn(schema);
				colvarPassWD.ColumnName = "passWD";
				colvarPassWD.DataType = DbType.String;
				colvarPassWD.MaxLength = 64;
				colvarPassWD.AutoIncrement = false;
				colvarPassWD.IsNullable = true;
				colvarPassWD.IsPrimaryKey = false;
				colvarPassWD.IsForeignKey = false;
				colvarPassWD.IsReadOnly = false;
				colvarPassWD.DefaultSetting = @"";
				colvarPassWD.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPassWD);
				
				TableSchema.TableColumn colvarDepid = new TableSchema.TableColumn(schema);
				colvarDepid.ColumnName = "DEPID";
				colvarDepid.DataType = DbType.Int32;
				colvarDepid.MaxLength = 0;
				colvarDepid.AutoIncrement = false;
				colvarDepid.IsNullable = true;
				colvarDepid.IsPrimaryKey = false;
				colvarDepid.IsForeignKey = false;
				colvarDepid.IsReadOnly = false;
				colvarDepid.DefaultSetting = @"";
				colvarDepid.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDepid);
				
				TableSchema.TableColumn colvarLevelID = new TableSchema.TableColumn(schema);
				colvarLevelID.ColumnName = "LevelID";
				colvarLevelID.DataType = DbType.Int32;
				colvarLevelID.MaxLength = 0;
				colvarLevelID.AutoIncrement = false;
				colvarLevelID.IsNullable = true;
				colvarLevelID.IsPrimaryKey = false;
				colvarLevelID.IsForeignKey = false;
				colvarLevelID.IsReadOnly = false;
				colvarLevelID.DefaultSetting = @"";
				colvarLevelID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLevelID);
				
				TableSchema.TableColumn colvarSecurityNum = new TableSchema.TableColumn(schema);
				colvarSecurityNum.ColumnName = "SecurityNum";
				colvarSecurityNum.DataType = DbType.Int32;
				colvarSecurityNum.MaxLength = 0;
				colvarSecurityNum.AutoIncrement = false;
				colvarSecurityNum.IsNullable = true;
				colvarSecurityNum.IsPrimaryKey = false;
				colvarSecurityNum.IsForeignKey = false;
				colvarSecurityNum.IsReadOnly = false;
				colvarSecurityNum.DefaultSetting = @"";
				colvarSecurityNum.ForeignKeyTableName = "";
				schema.Columns.Add(colvarSecurityNum);
				
				TableSchema.TableColumn colvarStatus = new TableSchema.TableColumn(schema);
				colvarStatus.ColumnName = "status";
				colvarStatus.DataType = DbType.Int32;
				colvarStatus.MaxLength = 0;
				colvarStatus.AutoIncrement = false;
				colvarStatus.IsNullable = true;
				colvarStatus.IsPrimaryKey = false;
				colvarStatus.IsForeignKey = false;
				colvarStatus.IsReadOnly = false;
				colvarStatus.DefaultSetting = @"";
				colvarStatus.ForeignKeyTableName = "";
				schema.Columns.Add(colvarStatus);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["CXDB"].AddSchema("CX_UserBase",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("UID")]
		[Bindable(true)]
		public int UID 
		{
			get { return GetColumnValue<int>(Columns.UID); }
			set { SetColumnValue(Columns.UID, value); }
		}
		  
		[XmlAttribute("Username")]
		[Bindable(true)]
		public string Username 
		{
			get { return GetColumnValue<string>(Columns.Username); }
			set { SetColumnValue(Columns.Username, value); }
		}
		  
		[XmlAttribute("PassWD")]
		[Bindable(true)]
		public string PassWD 
		{
			get { return GetColumnValue<string>(Columns.PassWD); }
			set { SetColumnValue(Columns.PassWD, value); }
		}
		  
		[XmlAttribute("Depid")]
		[Bindable(true)]
		public int? Depid 
		{
			get { return GetColumnValue<int?>(Columns.Depid); }
			set { SetColumnValue(Columns.Depid, value); }
		}
		  
		[XmlAttribute("LevelID")]
		[Bindable(true)]
		public int? LevelID 
		{
			get { return GetColumnValue<int?>(Columns.LevelID); }
			set { SetColumnValue(Columns.LevelID, value); }
		}
		  
		[XmlAttribute("SecurityNum")]
		[Bindable(true)]
		public int? SecurityNum 
		{
			get { return GetColumnValue<int?>(Columns.SecurityNum); }
			set { SetColumnValue(Columns.SecurityNum, value); }
		}
		  
		[XmlAttribute("Status")]
		[Bindable(true)]
		public int? Status 
		{
			get { return GetColumnValue<int?>(Columns.Status); }
			set { SetColumnValue(Columns.Status, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varUsername,string varPassWD,int? varDepid,int? varLevelID,int? varSecurityNum,int? varStatus)
		{
			CxUserBase item = new CxUserBase();
			
			item.Username = varUsername;
			
			item.PassWD = varPassWD;
			
			item.Depid = varDepid;
			
			item.LevelID = varLevelID;
			
			item.SecurityNum = varSecurityNum;
			
			item.Status = varStatus;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varUID,string varUsername,string varPassWD,int? varDepid,int? varLevelID,int? varSecurityNum,int? varStatus)
		{
			CxUserBase item = new CxUserBase();
			
				item.UID = varUID;
			
				item.Username = varUsername;
			
				item.PassWD = varPassWD;
			
				item.Depid = varDepid;
			
				item.LevelID = varLevelID;
			
				item.SecurityNum = varSecurityNum;
			
				item.Status = varStatus;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn UIDColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn UsernameColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn PassWDColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn DepidColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn LevelIDColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn SecurityNumColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        public static TableSchema.TableColumn StatusColumn
        {
            get { return Schema.Columns[6]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string UID = @"uID";
			 public static string Username = @"username";
			 public static string PassWD = @"passWD";
			 public static string Depid = @"DEPID";
			 public static string LevelID = @"LevelID";
			 public static string SecurityNum = @"SecurityNum";
			 public static string Status = @"status";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
